/*   1:    */package com.linkage.bss.commons.util;
/*   2:    */
/*   3:    */import java.text.ParseException;
/*   4:    */import java.text.SimpleDateFormat;
/*   5:    */import java.util.Date;
/*   6:    */import java.util.GregorianCalendar;
/*   7:    */import java.util.HashMap;
/*   8:    */import java.util.Map;
/*   9:    */
/*  31:    */public class DateUtil
/*  32:    */{
/*  33: 33 */  private static Map<String, SimpleDateFormat> formats = new HashMap();
/*  34:    */  
/*  35: 35 */  static { formats.put("yyyyMMddHHmmss", new SimpleDateFormat("yyyyMMddHHmmss"));
/*  36: 36 */    formats.put("yyyy-MM-dd HH:mm:ss", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
/*  37: 37 */    formats.put("yyyy-MM-dd", new SimpleDateFormat("yyyy-MM-dd"));
/*  38: 38 */    formats.put("MM/dd/yyyy HH:mm:ss a", new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a"));
/*  39: 39 */    formats.put("yyyy-MM-dd HH:mm:ss a", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss a"));
/*  40: 40 */    formats.put("yyyy-MM-dd'T'HH:mm:ss'Z'", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"));
/*  41: 41 */    formats.put("yyyy-MM-dd'T'HH:mm:ssZ", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"));
/*  42: 42 */    formats.put("yyyy-MM-dd'T'HH:mm:ssz", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz"));
/*  43: 43 */    formats.put("yyyyMMdd", new SimpleDateFormat("yyyyMMdd"));
/*  44: 44 */    formats.put("yyyy-MM-dd HH:mm:ss.SSS", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"));
/*  45: 45 */    formats.put("yyyyMMddHHmmss.SSS", new SimpleDateFormat("yyyyMMddHHmmss.SSS"));
/*  46:    */  }
/*  47:    */  
/*  50:    */  private static final String DATE_FORMATE_STRING_DEFAULT = "yyyyMMddHHmmss";
/*  51:    */  
/*  53:    */  private static final String DATE_FORMATE_STRING_A = "yyyy-MM-dd HH:mm:ss";
/*  54:    */  
/*  56:    */  private static final String DATE_FORMATE_STRING_B = "yyyy-MM-dd";
/*  57:    */  
/*  58:    */  private static final String DATE_FORMATE_STRING_C = "MM/dd/yyyy HH:mm:ss a";
/*  59:    */  
/*  60:    */  private static final String DATE_FORMATE_STRING_D = "yyyy-MM-dd HH:mm:ss a";
/*  61:    */  
/*  62:    */  public static String getFormatTimeString(Date date, String pattern)
/*  63:    */  {
/*  64: 64 */    SimpleDateFormat sDateFormat = getDateFormat(pattern);
/*  65: 65 */    return sDateFormat.format(date);
/*  66:    */  }
/*  67:    */  
/*  72:    */  public static String getDefaultFormateTimeString(Date date)
/*  73:    */  {
/*  74: 74 */    return getFormatTimeString(date, "yyyyMMddHHmmss");
/*  75:    */  }
/*  76:    */  
/*  80:    */  public static SimpleDateFormat getDateFormat(String pattern)
/*  81:    */  {
/*  82: 82 */    SimpleDateFormat sDateFormat = (SimpleDateFormat)formats.get(pattern);
/*  83: 83 */    if (sDateFormat == null) {
/*  84: 84 */      sDateFormat = new SimpleDateFormat(pattern);
/*  85: 85 */      formats.put(pattern, sDateFormat);
/*  86:    */    }
/*  87: 87 */    return sDateFormat;
/*  88:    */  }
/*  89:    */  
/*  92:    */  private static final String DATE_FORMATE_STRING_E = "yyyy-MM-dd'T'HH:mm:ss'Z'";
/*  93:    */  
/*  95:    */  private static final String DATE_FORMATE_STRING_F = "yyyy-MM-dd'T'HH:mm:ssZ";
/*  96:    */  
/*  97:    */  private static final String DATE_FORMATE_STRING_G = "yyyy-MM-dd'T'HH:mm:ssz";
/*  98:    */  
/*  99:    */  private static final String DATE_FORMATE_STRING_H = "yyyyMMdd";
/* 100:    */  
/* 101:    */  private static final String DATE_FORMATE_STRING_I = "yyyy-MM-dd HH:mm:ss.SSS";
/* 102:    */  
/* 103:    */  private static final String DATE_FORMATE_STRING_J = "yyyyMMddHHmmss.SSS";
/* 104:    */  
/* 105:    */  public static Date getDateFromString(String date, String pattern)
/* 106:    */    throws ParseException
/* 107:    */  {
/* 108:108 */    SimpleDateFormat sDateFormat = getDateFormat(pattern);
/* 109:109 */    return sDateFormat.parse(date);
/* 110:    */  }
/* 111:    */  
/* 115:    */  public static Date getDefaultDateFromString(String date)
/* 116:    */    throws ParseException
/* 117:    */  {
/* 118:118 */    return getDateFromString(date, "yyyyMMddHHmmss");
/* 119:    */  }
/* 120:    */  
/* 126:    */  public static String getNowDefault()
/* 127:    */  {
/* 128:128 */    return getNow("yyyyMMddHHmmss");
/* 129:    */  }
/* 130:    */  
/* 134:    */  public static String getNow(String pattern)
/* 135:    */  {
/* 136:136 */    return getFormatTimeString(new Date(), pattern);
/* 137:    */  }
/* 138:    */  
/* 145:    */  public static String getNowII()
/* 146:    */  {
/* 147:147 */    return getFormatTimeString(new Date(), "yyyyMMdd");
/* 148:    */  }
/* 149:    */  
/* 155:    */  public static long dateString2Long(String str, String pattern)
/* 156:    */    throws ParseException
/* 157:    */  {
/* 158:158 */    return getDateFromString(str, pattern).getTime();
/* 159:    */  }
/* 160:    */  
/* 165:    */  public static String longToDateStringDefault(long time)
/* 166:    */  {
/* 167:167 */    return getFormatTimeString(new Date(time), "yyyyMMddHHmmss");
/* 168:    */  }
/* 169:    */  
/* 174:    */  public static String longToDateString(long time, String pattern)
/* 175:    */  {
/* 176:176 */    return getFormatTimeString(new Date(time), pattern);
/* 177:    */  }
/* 178:    */  
/* 182:    */  public static long date2Long(Date date)
/* 183:    */  {
/* 184:184 */    return date.getTime();
/* 185:    */  }
/* 186:    */  
/* 190:    */  public static Date longToDate(long time)
/* 191:    */  {
/* 192:192 */    return new Date(time);
/* 193:    */  }
/* 194:    */  
/* 199:    */  public static Date getDateFromStringAdaptTwoPattern(String date)
/* 200:    */    throws ParseException
/* 201:    */  {
/* 202:    */    try
/* 203:    */    {
/* 204:204 */      return getDateFromString(date, "yyyy-MM-dd HH:mm:ss");
/* 205:    */    } catch (ParseException e) {}
/* 206:206 */    return getDateFromString(date, "yyyy-MM-dd");
/* 207:    */  }
/* 208:    */  
/* 215:    */  public static String getDIYDate(int count)
/* 216:    */  {
/* 217:217 */    StringBuffer dateStr = new StringBuffer();
/* 218:    */    
/* 219:219 */    GregorianCalendar date = new GregorianCalendar();
/* 220:220 */    date.add(2, count + 1);
/* 221:221 */    int year = date.get(1);
/* 222:222 */    int month = date.get(2);
/* 223:223 */    int day = date.get(5);
/* 224:224 */    int hour = date.get(11);
/* 225:225 */    int mi = date.get(12);
/* 226:226 */    int ss = date.get(13);
/* 227:227 */    if (month == 0) {
/* 228:228 */      month = 12;
/* 229:229 */      year--;
/* 230:    */    }
/* 231:231 */    dateStr.append(year);
/* 232:232 */    dateStr.append("-");
/* 233:233 */    dateStr.append(month);
/* 234:234 */    dateStr.append("-");
/* 235:235 */    dateStr.append(day);
/* 236:236 */    dateStr.append(" ");
/* 237:237 */    dateStr.append(hour);
/* 238:238 */    dateStr.append(":");
/* 239:239 */    dateStr.append(mi);
/* 240:240 */    dateStr.append(":");
/* 241:241 */    dateStr.append(ss);
/* 242:242 */    return dateStr.toString();
/* 243:    */  }
/* 244:    */}


/* Location:           E:\workspace\sungl111\workspace_promotion\BizHallConfig\WebRoot\WEB-INF\lib\bss.commons-0.1.jar
 * Qualified Name:     com.linkage.bss.commons.util.DateUtil
 * JD-Core Version:    0.7.0-SNAPSHOT-20130630
 */